﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class kecheng_kecheng_search_free : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            //Session["sTittle"] = "课程查询";
            Session["sUsername"] = "guest";
            Session["sUsername1"] = "来访者";
            Session["sRole"] = "学员";
            Session["sJigou"] = "远程教育平台";
            //以下取得参数（在masterpage中定义的zxdpkey,zxdptype2)
            string zxdkey = Request.QueryString["zxdpkey"];
            
            string zconj;
            if (zxdkey == "")
            {
                zconj = "1=1";
            }
            else
            {
                //zconj = "name='" + zxdkey + "'";
                zconj = "[name] like '%" + zxdkey + "%'";
            }
            //取得参数完毕
            
            zconj = "SELECT * FROM [kecheng] WHERE " + zconj + " AND [confirm]='终审通过' AND [fabuzt]='公开课程' ORDER BY [xtsj2] DESC";
            SqlDataSource1.SelectCommand = zconj;
        }
    }


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            int id = e.Row.RowIndex + 1;
            e.Row.Cells[0].Text = id.ToString();
        }

        
    }
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        if (e.NewSelectedIndex >= 0)
        {
            string zsql = "SELECT * from kecheng where id=" + GridView1.Rows[e.NewSelectedIndex].Cells[3].Text;
            SqlDataSource2.SelectCommand = zsql;
        }
        else
        {
            DetailsView1.Visible = false;
        }
    }


    protected void Button2_Click(object sender, EventArgs e)
    {
        
        
        string zconj = "[confirm]='终审通过' AND [fabuzt]='公开课程'";
        if (DropDownList1.SelectedValue.Length > 0)
        {
            zconj += " AND ([fenlei1] ='" + DropDownList1.SelectedValue + "')";
        }
        if (DropDownList2.SelectedValue.Length > 0)
        {
            zconj += " AND ([fenlei2] ='" + DropDownList2.SelectedValue + "')";
        }
        if (DropDownList3.SelectedValue.Length > 0)
        {
            zconj += " AND ([fenlei3] ='" + DropDownList3.SelectedValue + "')";
        }
        if (DropDownList4.SelectedValue.Length > 0)
        {
            zconj += " AND ([kechenglx] ='" + DropDownList4.SelectedValue + "')";
        }


        SqlDataSource1.SelectCommand = "SELECT * FROM [kecheng] WHERE " + zconj;

    }
    protected void Button3_Click(object sender, EventArgs e)
    {

        SqlDataSource1.SelectCommand = "SELECT * FROM [kecheng] WHERE [confirm]='终审通过' AND [fabuzt]='公开课程' ORDER BY [xtsj2] DESC";
        GridView1.DataBind();
        DropDownList1.SelectedIndex = -1;
        DropDownList2.SelectedIndex = -1;
        DropDownList3.SelectedIndex = -1;
        DropDownList4.SelectedIndex = -1;

    }

    protected void Button4_Click(object sender, EventArgs e)
    {

    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //if (e.CommandName.ToString() != "Select" & e.CommandName.ToString() != "Page" & e.CommandName.ToString() != "Sort")
        //{
        //    string zid = e.CommandArgument.ToString();
        //    //能成功运行的命令--Response.Write("<script language=javascript> window.open('../mystudy/kecheng_play.aspx','newwindow', 'height=768,width=1024,top=0,left=0,toolbar=no,resizable=yes,menubar=no,location=no,status=no')</script>");

        //    //修改后（加入参数传递）不能运行Response.Write("<script language=javascript> window.open('../mystudy/kecheng_play_temp.aspx?rid='"+zid+",'kecheng_play_window', 'height=768,width=1024,top=0,left=0,toolbar=no,resizable=yes,menubar=no,location=no,status=no')</script>");
        //    string zscript = "<script language=javascript> window.open('../mystudy/kecheng_play_temp.aspx?rid=" + zid + "','kecheng_play_window', 'height=768,width=1024,top=0,left=0,toolbar=no,resizable=yes,menubar=no,location=no,status=no')</script>";
        //    Response.Write(zscript);
        //}
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        //按照课程名称查询
        string noth = TextBox2.Text.Trim();
        
        SqlDataSource1.SelectCommand = "SELECT * FROM [kecheng] WHERE [fabuzt]='公开课程' AND [confirm]='终审通过' AND [name] like '%" + noth + "%'";
    }
}




    

